package com.zxl.gtion.controller;

import com.zxl.gtion.entity.Banner;
import com.zxl.gtion.entity.Video;
import com.zxl.gtion.service.BannerService;
import com.zxl.gtion.service.VideoService;
import com.zxl.gtion.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * (Banner)表控制层
 *
 * @author makejava
 * @since 2024-03-21 00:48:58
 */
@RestController
@RequestMapping("banner")
public class BannerController {
    /**
     * 服务对象
     */
    @Autowired
    private BannerService bannerService;
    @Autowired
    private VideoService videoService;

    /**
     * 获取视频横幅
     * @return 所有数据
     */
    @GetMapping("video")
    public R selectAll() {
        List<Banner> banners = bannerService.lambdaQuery().eq(Banner::getType, "0").list();
        for (Banner banner : banners) {
            Integer id = banner.getId();
            Video byId = videoService.getById(id);
            if (byId != null) {
                banner.setTitle(byId.getTitle());
                banner.setVideoUrl(byId.getVideoUrl());
            }
        }
        return R.ok(banners);
    }


}

